<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>购物网站</title>
        <link href="./css/bootstrap.css" rel="stylesheet">
    </head>
    <body>
        <?php session_start(); ?>
        <div class="container">
            <!-- 导航条开始 -->
            <nav class="navbar navbar-default" role="navigation">
                <a class="navbar-brand" style="font-family: 微软雅黑; font-size: 24px;" href="#">手机购物网站</a>
                <div id="navbar" class="navbar-collapse collapse">
                    <ul class="nav navbar-nav">
                        <li>
                            <a href="./displaycart.php">购物车(<?php echo count($_SESSION['cart']); ?>)</a>
                        </li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <?php if (isset($_SESSION['user'])) { ?>
                            <li><a href="#"><?php echo $_SESSION['user']['name']; ?></a></li>
                            <li><a href="logout.php">退出</a></li>
                        <?php } else { ?>
                            <li><a href="login.php">登录</a></li>
                        <?php } ?>
                    </ul>
                </div>
            </nav>
            <!-- 导航条结束 -->

            <!-- 商品列表开始 -->
            <div class="row">
                <?php require './mobile.php'; ?>
                <?php foreach ($mobiles as $id => $item) { ?>
                    <div class="col-sm-4 col-md-3 col-lg-3">
                        <div class="thumbnail">
                            <img src="<?php echo "./images/" . $item['image']; ?>"/>
                            <hr>
                            <div class="caption">
                                <p><?php echo $item['id']; ?></p>
                                <p><?php echo $item['name']; ?></p>
                                <p>￥<?php echo $item['price']; ?>元</p>
                                <p>
                                    <a class="btn btn-sm btn-primary" href="addtocart.php?pid=<?php echo $item['id']; ?>">添加到购物车</a>
                                </p>
                            </div>
                        </div>
                    </div>
                <?php } ?>
            </div>
            <!-- 商品列表结束 -->
        </div>
    </body>
</html>
